<template>
  <dt-modal-edit
    ref="edit"
    title="转交"
    :loading="loading"
    okText="确认"
    :width="400"
    @ok="onOk"></dt-modal-edit>
</template>

<script>
  import TransferOpt from './opt/transferOpt.js'
  import orgMgr from '@/biz/backStage/organizationManagement/index.js'
  import auditMgr from '@/biz/flowApproval/processAudit.js'

  export default {
    data() {
      return {
        info: {},
        loading: false
      }
    },
    mounted() {},
    methods: {
      onOk() {
        this.loading = true
        this.getAuth().then(() => {
          auditMgr
            .transfer(this.info)
            .then(() => {
              this.$Message.success('转交成功')
              this.loading = false
              this.$emit('success')
              this.hide()
            })
            .catch(() => {
              this.loading = false
            })
        })
      },
      getAuth() {
        return orgMgr
          .usUserAuth({
            userId: this.info.transmitUserId
          })
          .then((res) => {
            this.info.permissionIds = res.reduce((arr, item) => {
              if (item.permissionIds?.length) {
                arr = [...arr, ...item.permissionIds]
              }
              return arr
            }, [])
            return res
          })
      },
      show(info) {
        this.info = {
          auditId: info.auditId,
          transmitUserId: '',
          trAuditPeople: '',
          trWorkNo: '',
          permissionIds: []
        }
        this.$refs.edit.show(new TransferOpt(this.info))
      },
      hide() {
        this.$refs.edit.hide()
      }
    }
  }
</script>

<style lang="scss" scoped></style>
